/**
AirwayPathfinder for X-Plane Flight Simulator. Calculates the shortest path between two NavAids. 
Copyright (C) 2011  Nils Buletta

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 **/

package de.buletta.airwaypathfinder;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

/**
 * 
 * Represents the model for the table containing the information about the
 * computed path.
 * 
 * @author Nils Buletta
 * 
 */
public class PathTableModel extends AbstractTableModel {
	// TODO change this for final version
	private static final long serialVersionUID = 1L;
	private ArrayList<EarthNav> list;

	public PathTableModel(ArrayList<EarthNav> list) {
		this.list = list;
	}

	@Override
	public int getColumnCount() {
		return 4;
	}

	@Override
	public int getRowCount() {
		return list.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		switch (columnIndex) {
		case 0:
			return list.get(rowIndex).getIdentifier();
		case 1:
			return list.get(rowIndex).getPosition().getLatitude();
		case 2:
			return list.get(rowIndex).getPosition().getLongitude();
		}
		return "";
	}

	@Override
	public String getColumnName(int columnindex) {
		switch (columnindex) {
		case 0:
			return "Identifier";
		case 1:
			return "Latitude";
		case 2:
			return "Longitude";
		case 3:
			return "Altitude";
		}
		return "";
	}

	@Override
	public boolean isCellEditable(int row, int col) {
		// only the column for altitude is editable
		return col == 3 ? true : false;
	}

}
